import React, { useState } from 'react'
function useFrameUtil (context) {
    console.log(context)
    const [currentFrame,setCurrentFrame] = useState(0)
    const [startFrame,setStartFrame] = useState(0)
    const [startTime,setStartTime] = useState(new Date())
    const [realFps,setRealFps] = useState(120)
    const render = () => 
    {
        // context.font='20px 黑体';
        // context.fillText('fps: ' + realFps, 10,10)
    }
    const update = () => {
        const frameNo = currentFrame + 1
        setCurrentFrame(frameNo)
        const now = new Date()
        if (now - startTime >= 1000) {
            const fps = currentFrame - startFrame
            setRealFps(fps)
            setStartFrame(frameNo)
            setStartTime(now)
        } 
    }
    return {
        update,
        render
    }
}
export default useFrameUtil